﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Common;
using TRPOP.CRM.Component.DALSQLServer;
using TRPOP.CRM.Component.Model;

namespace TRPOP.CRM.Web
{
    /// <summary>
    /// 员工工作情况表
    /// </summary>
    public partial class EmployeeWorkLog_list : BaseAdmin
    {
        #region 权限限制
        protected override void SubPageInit()
        {
            base.m_oCurrentPermissionKey = "Employee_EmployeeWorkLog";
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                BindEmployee();
                BindData();
            }
        }
        /// <summary>
        /// 分页触发此事件（分页采用post方法传递数据）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void UC_PagerChanged(object sender, EventArgs e)
        {
            BindData();
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }
        #region 页面方法

        private void BindEmployee()
        {
            int intCount = 0;

            string strCondation = string.Format(" AND bIsDelete!={0} ", 1);

            ddlEmployee.DataSource = EmployeeManage.GetEmployeeSimpleInfoPager(1, int.MaxValue, strCondation, "iEmployeeID ASC", out intCount);

            ddlEmployee.DataTextField = "nvcEmployeeName";
            ddlEmployee.DataValueField = "iEmployeeID";

            ddlEmployee.DataBind();

            ddlEmployee.Items.Insert(0, new ListItem("全  部", "0"));

            //CompanyManage.UpdateRemindCompany();
        }
        protected void BindData()
        {
            string strCondation = string.Empty;
            int RecordCount = 0;
            // DateTime dt;
            if (ViewState["SearchCondation"] != null)
            {
                strCondation = ViewState["SearchCondation"].ToString();
            }

            if (ddlEmployee.SelectedValue.ToInt() > 0)
            {
                strCondation += " AND  iEmployeeID = " + ddlEmployee.SelectedValue.ToInt();
            }

            if (txtStartTime.Text.IsEmpty() == false && txtEndTime.Text.IsEmpty() == false)
            {
                strCondation += "AND dtCreationTime Between '" + txtStartTime.Text.ToDateTime() + "' and '" + txtEndTime.Text.ToDateTime() + "'";
            }

            rptList.DataSource = CompanyManage.GetWorkingLogPager(Pager.CurrentPage, Pager.PageSize, strCondation, string.Empty, out RecordCount);

            rptList.DataBind();

            Pager.RecordCount = RecordCount;

            Pager.Page_ReLoad();
        }
        #endregion
        public static string backEmolyeeName(int id)
        {
            EmployeeDAL employdal = new EmployeeDAL();
            EmployeeInfo employee = employdal.GetInfoById(id);
            string name = employee.nvcEmployeeName;
            return name;
        }
    }
}